package com.zzyk.main.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzyk.main.mapper.SysLogDao;
import com.zzyk.main.model.pojo.SysLog;
import com.zzyk.main.model.vo.LogInfo;
import com.zzyk.main.model.vo.TimePair;
import com.zzyk.main.service.ISysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SysLogServiceImpl implements ISysLogService {

    @Autowired
    private SysLogDao sysLogDao;

    @Override
    public int addLog(SysLog sysLog) {
        return sysLogDao.insertLog(sysLog);
    }

    @Override
    public String[] getOperas() {
        List<SysLog> infoList = sysLogDao.getOperationsByGroup();
        String[] operations = new String[infoList.size()];
        for (int i = 0; i < infoList.size(); i++) {
            operations[i] = infoList.get(i).getOpera();
        }
        return operations;
    }

    @Override
    public PageInfo<LogInfo> getLogList(String operation, String searchValue, Date startTime, Date endTime, int currentPage, int pageSize, Integer id) {
        PageHelper.startPage(currentPage, pageSize);
      /*  TimePair timePair = TimePair.checkTime(startTime, endTime);
        startTime = timePair.getStartTime();
        endTime = timePair.getEndTime();*/
        return new PageInfo<>(sysLogDao.getLogList(operation, searchValue, startTime, endTime,id));
    }

    @Override
    public List<LogInfo> exportLogList(String operation, String searchValue, Date startTime, Date endTime) {
        TimePair timePair = TimePair.checkTime(startTime, endTime);
        startTime = timePair.getStartTime();
        endTime = timePair.getEndTime();
        return sysLogDao.getLogList(operation, searchValue, startTime, endTime, null);
    }
}
